#include <stdlib.h>
#include <stdio.h>
#include <log4cplus/logger.h>
#include <log4cplus/consoleappender.h>
#include <log4cplus/fileappender.h>
#include <log4cplus/layout.h>
#include <log4cplus/loglevel.h>
#include <log4cplus/ndc.h>
#include <log4cplus/configurator.h>
#include <log4cplus/loggingmacros.h>
using namespace log4cplus;
using namespace log4cplus::helpers;

int main()
{
    /* step 1: Instantiate an appender object */
    SharedAppenderPtr _append(new ConsoleAppender());
    _append->setName("append for test");
    /* step 2: Instantiate a layout object */
    std::string pattern = "%d{%m/%d/%y %H:%M:%S}  - %m [%l]%n";
    std::auto_ptr<Layout> _layout(new PatternLayout(pattern));
    /* step 3: Attach the layout object to the appender */
    _append->setLayout( _layout );
    /* step 4: Instantiate a logger object */
    Logger _logger = Logger::getInstance("test");
    /* step 5: Attach the appender object to the logger  */
    _logger.addAppender(_append);
    /* step 6: Set a priority for the logger  */
    _logger.setLogLevel(ALL_LOG_LEVEL);
    /* log activity */
    LOG4CPLUS_DEBUG(_logger, "This is the FIRST log message...") ;
    sleep(1);
    LOG4CPLUS_WARN(_logger, "This is the SECOND log message...")  ;

    //output to file
    /* step 1: Instantiate an appender object */
    SharedAppenderPtr _append2(new FileAppender("Test.log"));
    _append2->setName("file log test");
    /* step 4: Instantiate a logger object */
    Logger _logger2 = Logger::getInstance("test.subtestof_filelog");
    /* step 5: Attach the appender object to the logger  */
    _logger2.addAppender(_append2);
    /* log activity */
    int i;
    for( i = 0; i < 5; ++i )
    {
        LOG4CPLUS_DEBUG(_logger2, "Entering loop #" << i << "End line #");
    }
    return 0;
}
